package com.ant.collect.controller;


import com.ant.collect.common.ResultVo;
import com.ant.collect.dto.EnvironmentalDto;
import com.ant.collect.handler.AntException;
import com.ant.collect.service.IEnvironmentalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hzd
 * @since 2025-10-23
 */
@RestController
@RequestMapping("/environmental")
@Api(tags = "原辅料信息接口")
public class EnvironmentalController {

    @Autowired
    IEnvironmentalService environmentalService;

    @ApiOperation(value = "获取信息分页")
    @GetMapping("/getEnvironmentalPage")
    public ResultVo getEnvironmentalPage(EnvironmentalDto dto) {
        Map<String, Object> map = environmentalService.getEnvironmentalPage(dto);
        return ResultVo.success(map);
    }

    @ApiOperation(value = "获取信息列表")
    @GetMapping("/list")
    public ResultVo list(){
        return ResultVo.success("ok",environmentalService.list());
    }

    @ApiOperation(value = "保存信息")
    @PostMapping("/save")
    public ResultVo save(@RequestBody EnvironmentalDto dto)
    {
           environmentalService.save(dto);
           return ResultVo.success("添加成功");
    }

    @ApiOperation(value = "通过产品id获取辅料列表")
    @GetMapping("/listById")
    @ApiImplicitParam(name = "id", value = "产品id", required = true,dataType = "Integer", paramType = "query")
    public ResultVo listById(Integer id){
        if(id==null){
            throw new AntException("请输入产品id");
        }
        return ResultVo.success("ok",environmentalService.listById(id));
    }

}
